package DictData;

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import BufferReader.BufferReader;
import RawDict.MeanTag;

public class OxfordWordInfo extends BaseDictData {

	public static int MaxSound = 2;

	protected int soundInfo[] = null;

	public OxfordWordInfo(){
		super();
	}
	
	public OxfordWordInfo(int itemsSize){
		super(itemsSize);
	}
	
	public int GetSoundNum(){
		int soundNum = 0;
		int soundItemID = MeanTag.Phonetic.ordinal();
		for(BaseDictData group : groups){
			if(group.items[soundItemID] != null){
				++soundNum;
			}
		}
		return soundNum > 1 ? soundNum : 1;
	}
	
	@Override
	protected void WriteInfo(DataOutputStream writer) throws IOException{
		if(soundInfo != null){
			assert(soundInfo.length > 1);
			writer.writeByte(soundInfo.length);
			for(int i : soundInfo){
				writer.writeInt(i);
			}
		}
		else{
			writer.writeByte(0);
		}
		super.WriteInfo(writer);
	}
	
	@Override
	protected void ReadInfo(BufferReader reader){
		int numSoundInfo = reader.ReadByte();
		if(numSoundInfo > 0){
			assert(numSoundInfo > 1);
			soundInfo = new int[numSoundInfo];
			for(int i=0; i<numSoundInfo; ++i){
				soundInfo[i] = reader.ReadInt();
			}
		}
		super.ReadInfo(reader);
	}

	public void SetSoundInfo(ArrayList<Integer> infos) {
		if(infos.size() != 0){
			soundInfo = new int[infos.size()];
			for(int i=0; i<infos.size(); ++i){
				soundInfo[i] = infos.get(i);
			}
		}
	}

	public void Build(DataOutputStream dstDictWriter) throws IOException {
		Write(dstDictWriter);
	}
}
